11/9 DH 면접 스터디

@VERO
Created Date · 2023년 11월 09일 02:11
Last Updated Date · 2023년 11월 09일 06:11

문제

So I'll copy the question right over.

Given a non-empty array of integers, return the k most frequent elements.

Example 1: Input: nums = [1, 1, 1, 2, 2, 3], k = 2 Output: [1, 2]

Example 2: Input: nums = [1], k = 1 Output: [1]

Note: Assume k is always valid. The input array will always have k unique most frequent elements.

For example, if nums = [1, 1, 2, 2, 3, 3], k cannot be 2 because there are no 2 unique most frequent elements. Inthis example, the only valid k is 3.

mock interview